package com.iwhale.cxm.mail.service;

import com.alibaba.dubbo.rpc.service.GenericService;
import com.iwhale.cxm.mail.controller.DubboInvoke;
import com.taobao.hsf.app.api.util.HSFApiConsumerBean;
import org.springframework.stereotype.Service;

/**
 * <P></P>
 *
 * @author zhong.fuhua@iwhalecloud.com
 * @since
 */
@Service
public class DubboInvokeService {

    public Object invoke(DubboInvoke dubboInvoke) throws Exception {
        HSFApiConsumerBean consumerBean = new HSFApiConsumerBean();
        consumerBean.setInterfaceName(dubboInvoke.getInterfaceName());
        consumerBean.setVersion(dubboInvoke.getVersion());
        //consumerBean.setClientTimeout(param.getTimeout());
        //consumerBean.setRetries(param.getRetrys());
        consumerBean.setGeneric("true");
        consumerBean.init(true);

        GenericService genericService = (GenericService) consumerBean.getObject();
        return genericService.$invoke(dubboInvoke.getMethod(), dubboInvoke.getParamType(), dubboInvoke.getParam());
    }

}
